import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
} from '@nestjs/common'
import { UserService } from './user.service'
import { CreateUserDto } from './dto/create-user.dto'
import { UpdateUserDto } from './dto/update-user.dto'
import { ApiTags, ApiOperation } from '@nestjs/swagger/dist'
import { query } from 'express'

@Controller('user')
@ApiTags('用户')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @ApiOperation({ summary: '用户发表文章的接口' })
  @Post('/add/post')
  addTags(
    @Body()
    params: {
      title: string
      userId: string
      content: string
      discuss?: string
      topic?: string
      imgArray?: string[]
      address?: string
    }
  ) {
    return this.userService.addPost(params)
  }
  @ApiOperation({ summary: '添加关注的接口' })
  @Post('add/follows')
  addFollows(@Body() query: { userId: string,followsId:string }) {
    return this.userService.addFollows(query)
  }
  @ApiOperation({ summary: '添加粉丝的接口' })
  @Post('add/fans')
  addFans(@Body() query: { userId: string,fansId:string }) {
    return this.userService.addFans(query)

  }


  @Post()
  create(@Body() createUserDto: CreateUserDto) {
    console.log('收到的数据', createUserDto)
    return this.userService.create(createUserDto)
  }
  @ApiOperation({ summary: '模糊查找用户' })
  @Get('keywords')
  findLike(@Query() query: { keyword: string }) {
    return this.userService.findLike(query)
  }
  @Get('post')
  findPostByPage(@Query() query: {  userId?: string,page?: number, pageSize?: number }) {
    return this.userService.findPostByPage(query)
  }
  @Get('all')
  findAll() {
    return this.userService.findAll()
  }
  @Get('login')
  login(@Query() query:{mobile:string,password:string}) {
    return this.userService.login(query)
  }
  @Get(':id')
  findOne(@Param('id') id: string) {
    console.log(id)
    return this.userService.findOne(id)
  }


  @ApiOperation({ summary: '用户修改个人信息' })
  @Patch(':id')
  update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
    this.userService.update(id, updateUserDto)
    return this.userService.findOne(id)
  }


  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userService.remove(+id)
  }
}
